<?php

class ProfileController extends ControllerBase
{

    public function indexAction()
    {
		$this->view->setMainView('index');
		$this->view->setVar('page_name', 'Profile');
		$this->view->setVar('content', 'profile/index');
		$this->view->setVar('title','|' . $this->session->get('fullname'));
		
		$user_id = $_GET['bhd'];
		$feeds = UserFeedsTb::listProfileFeeds($user_id);
		


		$info = UserAccountTb::findFirstById($user_id);
		if($info == false || $this->session->get('user_id') == null)
		{
			header("Location: ".BASE_URI);
		}
		
		$this->view->setVar('feeds',$feeds);
		$this->view->setVar('info',$info);
		
		//GET REQUESTS
		$requests = ConnectionRequestTb::listRequest($user_id);
		$connections = UserConnectionsTb::listConnection($user_id);

		$paginator = new \Phalcon\Paginator\Adapter\Model(
		    array(
		        "data" => $requests,
		        "limit"=> 10,
		        "page" => 1
		    )
		);

		// Get the paginated results
		$request_page = $paginator->getPaginate();
		$this->view->setVar('requests_page',$request_page);

		$paginator = new \Phalcon\Paginator\Adapter\Model(
		    array(
		        "data" => $connections,
		        "limit"=> 10,
		        "page" => 1
		    )
		);

		// Get the paginated results
		$connection_page = $paginator->getPaginate();
		$this->view->setVar('connection_page',$connection_page);





	}
    public function feedsAction()
    {
		$this->view->setMainView('index');
		$this->view->setVar('page_name', 'Feeds');
		$this->view->setVar('content', 'profile/feeds');
	}

	public function listPendingAction()
	{
		//if($this->request->isPost() == false) die('Not a post');
			$user_id = $this->session->get('user_id');
			$request = ConnectionRequestTb::listRequest($user_id);

			foreach ($request as $value) {
			$data[] = array(
				"id" => $value->crt->sender_id,
				"profile_pic" => $value->uat->profile_pic,
				"fname" => $value->uat->fname,
				"lname" => $value->uat->lname
				);
		}

		echo json_encode($data);
		$this->view->disable();	
	}

}

